//
// AnimatedWidget.cs
//
// Copyright (C) 2008 Lukas Lipka <lukaslipka@gmail.com>
//

using System;
using System.Collections.Generic;

using Gtk;
using Gdk;

using Dashboard.Mint.Theatrics;

namespace Dashboard.Mint.Widgets {

	public class AnimatedWidget : Gtk.EventBox {

		private Requisition child_requisition;

		private Stage<AnimatedWidget> stage = new Stage<AnimatedWidget> ();
		private Actor<AnimatedWidget> actor = null;

		public AnimatedWidget (uint duration)
		{
			actor = new Actor<AnimatedWidget> (this, duration);
			actor.Stepped += OnStep;
			stage.Add (actor);
		}

		public void Shrink ()
		{
			stage.Start ();
		}

		public void Grow ()
		{
			stage.Start ();
		}

		private void OnStep (AnimatedWidget widget)
		{
			QueueResizeNoRedraw ();
		}

		protected override void OnSizeRequested (ref Requisition requisition)
		{			
			child_requisition = Children[0].SizeRequest ();

			requisition.Width = child_requisition.Width; //(int) (actor.Percent * child.Width);
			requisition.Height = (int) (actor.Percent * child_requisition.Height);
		}

		protected override void OnSizeAllocated (Rectangle allocation)
		{
			//allocation.Width = child_requisition.Width;
			allocation.Height = child_requisition.Height;

			base.OnSizeAllocated (allocation);
		}
	}
}
